/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once


#include "物理/intern/S_Physics.h"




struct S_PhysicsMPM : public S_Physics {
	
	S_GPU内存块 m_坐标;
	S_GPU内存块 m_速度;
	S_GPU内存块	m_质量;
	S_GPU内存块	m_速度梯度;

	S_GPU内存块 m_网格速度;
	S_GPU内存块 m_网格质量;

	S_GPU内存块 m_网格速度_原子正;
	S_GPU内存块 m_网格速度_原子负;
	S_GPU内存块 m_网格权重_原子正;
	S_GPU内存块 m_网格权重_原子负;


	vec3	m_域偏移;
	uvec3	m_网格分辨率;
	float32	m_网格单元大小;


	S_设备环境 m_Ctx;
	S_GPU计算* m_GPU计算_粒子赋予到网格;
	S_GPU计算* m_GPU计算_网格初始化;
	S_GPU计算* m_GPU计算_网格更新;
	S_GPU计算* m_GPU计算_网格更新到粒子;


	static C_StrKey分配器	g_名称生成器;

	S_PhysicsMPM(S_设备环境& ctx, std::wstring name = L"mpm");
	~S_PhysicsMPM();

	void	f_Update();

	void	f_粒子施加力();
	void	f_粒子赋予到网格();
	void	f_网格解算();
	void	f_网格更新到粒子();
	
};



S_Physics*	f_phy_创建MPM(S_设备环境& ctx);
void		f_phy_销毁MPM(S_Physics* phy);


void f_mpm_重置(S_PhysicsMPM& mpm);

void f_mpm_设置MPM网格维度(S_Physics* phy, const vec3& 网格大小, const vec3& 域偏移, float32 单元大小);

void f_mpm_添加物理体(S_Physics* phy, S_PhyBodyArray* body);

void f_mpm_解算(S_PhysicsMPM* mpm, float32 时间步进);

void f_mpm_取调试粒子(S_Physics* phy, S_物体* ob);



